import java.util.HashSet;
import java.util.Set;

/**
 * @author LKQ
 * @date 2022/2/25 17:17
 * @description
 */
public class Solution2 {
    public static void main(String[] args) {
        Solution2 solution2 = new Solution2();
        solution2.subarrayBitwiseORs(new int[]{1, 4, 3, 3, 2});
    }
    public int subarrayBitwiseORs(int[] A) {
        Set<Integer> set = new HashSet<>();
        int n = A.length;
        if (n < 2) {
            return n;
        }
        for (int i = 0; i < n; i++) {
            set.add(A[i]);
            for (int j = i-1; j >= 0; j--) {
                if ((A[j] | A[i]) == A[j]) {
                    // 从后往前遍历，发现或之后找到重复，那么跳出循环
                    break;
                }
                A[j] |= A[i];
                set.add(A[j]);
            }
        }
        return set.size();
    }
}
